#!/bin/sh

if [ $# != "2" ]; then
	echo Syntax: oldword newword	
	exit
fi
  

echo "Replacing $1 with $2 for real ? [y/n] "

read answer

case "$answer" in
y*)
	echo Confirmed, swapping words ... ;;
*)
	echo Canceled, exiting.
	exit;;
esac

for i in `find . -name "*.c" -o -name "*.h" -o -name Makefile | xargs`;
do
	echo Swapping inside file $i

	cat $i | sed s/"$1"/"$2"/g > $i.new && mv $i.new $i \
	    || (echo Errors, exiting && exit)

done

echo Words replaced.
	